window.name="picList";


var tableIn;
var table = null;
var form;
<!--    刷新方法-->
function refresh(){
    tableIn.reload('btable');
}
<!--    刷新全局-->
$('#refreshall').click(function (){
    location.reload();

})

// 返回上页
$('#returnsuper').click(function (){
    layer.msg("还没写呢，回去了",{time:500});
    // window.location.href="../index.html";

})

layui.use(['table','form'],function (){
    table = layui.table;
     form= layui.form;

    tableIn = table.render({
        elem:'#demo',
        id:'btable',
        page:{// 分页方法
            limit:10
            ,limits:[5,10,20,30]
            ,layout:['count','prev','page','next','limit']
            ,groups:5
        },
        height:500,
        url:'/manager/advertiding/getAll',
        cols:[
            [
                {field: '',type:'checkbox'},
                {field:'number',title: '数据编号',hide:'true'},
                {field:'userNum',title:'用户ID',align:'center'},
                {field: 'imageUrl',title: '图片地址',align:'center',height:100,templet:function (d){
                        return '<div><img src="'+d.imageUrl+'",'+'style="width:50px;height:50px;"></div>'
                    }},
                {field: 'createrUser',title: '创建人',align:'center',templet:function (obj){
                        if(obj.createrUser == 0){
                            return "思云系统管理员";
                        }else if(obj.createrUser == 1){
                            return "思云系统运营人员";
                        }else if(obj.createrUser == 2){
                            return '思云系统创作者';
                        }else {
                            return '思云用户';
                        }
                    }},
                {field: 'imageTitle',title:'图片标题',align:'center'},
                {field: 'imageType',title:'图片类型',align:'center'},
                {field: 'remarks',title:'备注',align:'center'},
                {field: 'expireTime',title:'更新时间',align:'center'},
                {field: '',title: '操作',toolbar:'#toolb',align:'center'}
            ]
        ],
        parseData:function (res){
            return{
                "code":res.state,//解析接口状态
                "msg":res.message,//解析提示文本
                "count":res.total,//解析数据长度
                "data":res.data//解析数据列表
            }
        }

    })

    //行工具栏监听
    table.on('tool(test)',function (obj){
        var e = obj.event;
        var data = obj.data;
        if(e == 'del')  {
            $.ajax({
                url:'/manager/advertiding/del',
                type: 'post',
                data:{
                    "number":data.number
                },
                dataType:'json',
                success:function (d){
                    layer.msg(d.message,{time:500,icon:6});
                    refresh();
                }
            })
        }else if(e =='update'){
            localStorage.setItem("isOnline",data.isOnline)
            localStorage.setItem("imageUrl",data.imageUrl);
            localStorage.setItem("videoUrl",data.videoUrl);
            localStorage.setItem("imageType",data.imageType);
            localStorage.setItem("startTime",data.startTime);
            localStorage.setItem("expireTime",data.expireTime);
            layer.open({
                type:2,
                content:'picupdate.html',
                title:'修改数据',
                area:['95%','95%'],
                success:function (layero,index){
                    //    获取iframe层dom对象
                    var childFrame = layer.getChildFrame('body',index);
                    //    操作iframe层dom对象  父页面的数据传入到子类
                    childFrame.find('input[name="imageTitle"]').val(data.imageTitle);
                    childFrame.find('input[name="number"]').val(data.number);
                    childFrame.find('input[name="imageType"]').val(data.imageType);
                    childFrame.find('input[name="startTime"]').val(data.startTime);
                    childFrame.find('input[name="expireTime"]').val(data.expireTime);
                    childFrame.find('input[name="isOnline"]').val(data.isOnline);
                    childFrame.find('input[name="imageUrl"]').val(data.imageUrl);
                    childFrame.find('input[name="videoUrl"]').val(data.videoUrl);
                    console.log(data);
                }
            })
        }
    })
    //搜索栏
    form.on('submit(go)',function (d){
        var data = d.field;
        var imageType = data.imageType;
        var isOnline = data.isOnline;
        var url = data.url;
        console.log(imageType+"  "+isOnline);
        table.reload('btable',{
            url:'/manager/advertiding/getCaByType',//后台做模糊搜索接口路径
            method:'post',
            where:{//可传多个参数到后台... ，分隔
                imageType:imageType
                ,isOnline:isOnline
            },
            page:{
                cuur:1//重新从第 1 页开始
            }
        })
        return false;
    })


    //    use最后
})
